package com.hyperzsoft.budget;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.widget.Toast;

import com.hyperzsoft.budget.DBProvider.BudgetTable;

public class CreateData {
	private DBProvider dbProvider;
	
	static private int AmberColor;// = "#FFBF00";
	static private int RedColor;// = "#DD0000";
	static private int GreenColor;// = "#88BB44";
	static private int GroupHeaderColor;// = "5500FF";
	
	public void createDefaultGroupsAndItems(Context context) {
		long amberID;
		long redID;
		long greenID;
		
		try {
			dbProvider = new DBProvider(context);
			dbProvider.open();
			DBProvider.ExpenseType expenseType;
			DBProvider.Expense expense;
			DBProvider.Period period;
			
			dbProvider.deleteAll(BudgetTable.EXPENSE);
			dbProvider.deleteAll(BudgetTable.EXPENSE_TYPE);
			
			//set default colors
			AmberColor = Color.rgb(255, 191, 0);
			RedColor = Color.rgb(221, 0, 0);
			GreenColor = Color.rgb(136, 187, 68);
			
			GroupHeaderColor = Color.rgb(55, 0, 255);
			
			//create the types
			expenseType = dbProvider.new ExpenseType();
			expenseType.NAME = "Monthly Expense";
			expenseType.COLOR = RedColor;
			expenseType.TYPE_OF = dbProvider.EXPENSE_TYPES;
			expenseType.insert();
			redID = expenseType._ID;
			
			expenseType = dbProvider.new ExpenseType();
			expenseType.NAME = "Irregular Expense";
			expenseType.COLOR = AmberColor;
			expenseType.TYPE_OF = dbProvider.EXPENSE_TYPES;
			expenseType.insert();
			amberID = expenseType._ID;
			
			expenseType = dbProvider.new ExpenseType();
			expenseType.NAME = "Cash Expense";
			expenseType.COLOR = GreenColor;
			expenseType.TYPE_OF = dbProvider.EXPENSE_TYPES;
			expenseType.insert();
			greenID = expenseType._ID;
			
			//create first group, which is a type 1
			expenseType = dbProvider.new ExpenseType();
			expenseType.NAME = "Housing Expenses";
			expenseType.COLOR = GroupHeaderColor;
			expenseType.TYPE_OF = dbProvider.EXPENSE_GROUPS;
			expenseType.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Rent";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 775.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Cell Phone";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 50.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Internet";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 10.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Household";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = amberID;
			expense.AMOUNT = 30.00;
			expense.insert();
			
			expenseType = dbProvider.new ExpenseType();
			expenseType.NAME = "Living Expenses";
			expenseType.COLOR = GroupHeaderColor;
			expenseType.TYPE_OF = dbProvider.EXPENSE_GROUPS;
			expenseType.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Groceries";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 400.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Bus/Taxi";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 70.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Specialists";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = greenID;
			expense.AMOUNT = 50.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Eye Care";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = amberID;
			expense.AMOUNT = 25.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Prescriptions";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = greenID;
			expense.AMOUNT = 65.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Other Health Expenses";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = amberID;
			expense.AMOUNT = 25.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Bank Fees/Safety Box";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = greenID;
			expense.AMOUNT = 25.00;
			expense.insert();
			
			expenseType = dbProvider.new ExpenseType();
			expenseType.NAME = "Work Expenses";
			expenseType.COLOR = GroupHeaderColor;
			expenseType.TYPE_OF = dbProvider.EXPENSE_GROUPS;
			expenseType.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Lunches/Breaks";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = greenID;
			expense.AMOUNT = 40.00;
			expense.insert();
			
			expenseType = dbProvider.new ExpenseType();
			expenseType.NAME = "Personal Expenses";
			expenseType.COLOR = GroupHeaderColor;
			expenseType.TYPE_OF = dbProvider.EXPENSE_GROUPS;
			expenseType.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Clothing & Shoes";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = amberID;
			expense.AMOUNT = 50.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Fitness Membership";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = greenID;
			expense.AMOUNT = 85.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Eating Out";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = amberID;
			expense.AMOUNT = 50.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Entertainment";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = amberID;
			expense.AMOUNT = 20.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Hair Care";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = amberID;
			expense.AMOUNT = 15.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Gifts/Special Occasions";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = amberID;
			expense.AMOUNT = 35.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Travel/Vacations";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = amberID;
			expense.AMOUNT = 50.00;
			expense.insert();
			
			expenseType = dbProvider.new ExpenseType();
			expenseType.NAME = "Debt Payments";
			expenseType.COLOR = GroupHeaderColor;
			expenseType.TYPE_OF = dbProvider.EXPENSE_GROUPS;
			expenseType.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Money to Family";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 175.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Other Debt";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 200.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "Savings";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 25.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "RRSP";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 50.00;
			expense.insert();
			
			expense = dbProvider.new Expense();
			expense.NAME = "CCS of BC";
			expense.GROUP_ID = expenseType._ID;
			expense.TYPE_ID = redID;
			expense.AMOUNT = 1200.00;
			expense.insert();
			
//			period = dbProvider.new Period();
//			period.START_DATE = Date.valueOf("2011-06-10").getTime();
//			period.COMMENT = "";
//			period.EARNINGS = 1763.00;
//			period.START_AMOUNT = 0.00;
//			period.TOTAL_PAID = 0.00;
//			period.END_AMOUNT = 0.00;
//			period.UPDATED_DATE = DateUtils.now();
//			
//			period = dbProvider.new Period();
//			period.START_DATE = Date.valueOf("2011-06-24").getTime();
//			period.COMMENT = "";
//			period.EARNINGS = 1763.00;
//			period.START_AMOUNT = 0.00;
//			period.TOTAL_PAID = 0.00;
//			period.END_AMOUNT = 0.00;
//			period.UPDATED_DATE = DateUtils.now();
//			
//			period = dbProvider.new Period();
//			period.START_DATE = Date.valueOf("2011-05-13").getTime();
//			period.COMMENT = "";
//			period.EARNINGS = 1763.00;
//			period.START_AMOUNT = 0.00;
//			period.TOTAL_PAID = 0.00;
//			period.END_AMOUNT = 0.00;
//			period.UPDATED_DATE = DateUtils.now();
//			
//			period = dbProvider.new Period();
//			period.START_DATE = Date.valueOf("2011-05-27").getTime();
//			period.COMMENT = "";
//			period.EARNINGS = 1763.00;
//			period.START_AMOUNT = 0.00;
//			period.TOTAL_PAID = 0.00;
//			period.END_AMOUNT = 0.00;
//			period.UPDATED_DATE = DateUtils.now();
			
			dbProvider.close();
			Toast.makeText(context, "Database Created", Toast.LENGTH_LONG).show();
		} catch (Exception e) {
			Log.e("Create Data Process", e.toString());
		}
	}
}